//
//  HRDeliveryTimeViewController.m
//  haierapp
//
//  Created by Xia Zhiyong on 14-8-14.
//  Copyright (c) 2014年 haier. All rights reserved.
//

#import "HRDeliveryTimeViewController.h"
#import "HRDeliveryTimeTableViewCell.h"

@interface HRDeliveryTimeViewController (){
    NSArray *arrayTypes;
    NSInteger currentSelect;
    NSArray *arrayCode;
}

@end

@implementation HRDeliveryTimeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        arrayTypes = [[NSArray alloc] initWithObjects:@"不限送货时间（周一至周日）",@"工作日（周一至周五）",@"休息日（周六、周日）", nil];
        arrayCode = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (__CUR_IOS_VERSION >= __IPHONE_7_0)
    {
        self.edgesForExtendedLayout= UIRectEdgeNone;
    }
    self.navigationItem.title = @"送货时间";
    currentSelect = 0;

}

#pragma mark - UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return arrayTypes.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"HRDeliveryTimeTableViewCell";
    HRDeliveryTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[HRDeliveryTimeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    }
    
    if (currentSelect == indexPath.row) {
        cell.btnSelect.selected = YES;
    }else{
        cell.btnSelect.selected = NO;
    }
    cell.lblTime.text = [arrayTypes objectAtIndex:indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    currentSelect = indexPath.row;
    [tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)actionSure:(id)sender {
    NSString *str = [arrayTypes objectAtIndex:currentSelect];
    NSString *code = [arrayCode objectAtIndex:currentSelect];
    if (_chooseTime) {
         _chooseTime(str,code);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
@end
